package sharedServlets;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class C2DMRegistrationServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Logger log = Logger.getLogger("C2DMRegistrationServlet");
		C2DM c2dm = C2DM.getInst();

		log.warning("start");
		String register = req.getParameter("reg");
		String userName = req.getParameter("userName");
		String error = req.getParameter("error");
		log.warning("userName: "+userName);
		log.warning("error: "+error);
		if(register!=null && register.equals("true") && userName!=null){
			String id = req.getParameter("id");			
			log.warning("id: "+id);
			if(id!=null){
				//t.sendMessage("DQAAALwAAAD0qzYHBpyEb4MiZJt0Mnrwo18sd2MdCmkyZhLdTGExDS7cSE_Xo-FTE7xM_FcE2sYiRIQjOAVDyHYnDZ-ZOH9do8Az9dU4fW7c4y0cGxZ8wpcfF7-gQQmfIMGuS3g_VRdwnsJ4-W7Rm3xPkxDjVCHA4ggdqJksBKM5fVBv1IUFabA-2cFVjLyFYcuSgaZqgKDvrn22kEPO2hQsYaA45u4YMp4-hpZjjTW83gdIayaXyDF_bGN5y9BFSf06zcduo34",id,"HIIIIII!!!!!");
				c2dm.register(userName, id);
			}
			log.warning("after sending");
		}
		else if(userName!=null){
			c2dm.unregister(userName);
		}
	}
}
